/**
 * 
 */
package application;

import java.util.List;

import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.MongoTemplate;

import com.game.data.dao.example.PersonDAO;
import com.game.factory.GameBeanFactory;
import com.game.factory.SpringUtil;
import com.game.model.example.Address;
import com.game.model.example.Person;
import com.game.model.example.ZipCode;


/**
 * 服务器启动入口
 * @author Quake
 */
public class GameApplication {
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		SpringUtil.init();
		//启动服务器
		NetServer.getInstances();
		test1();
//		test2();
//		save();
	}
	
	public static void save() {
		PersonDAO personDAO = GameBeanFactory.getPersonDAO();
		Person person = new Person(32644, "st", "fe", 633, 123);
		person.setAddress(new Address("cn",	 "chengdu", "street", new ZipCode("123456")));
		String id = new ObjectId().toString();
		System.out.println(id);
		person.setId(id);
		personDAO.save(person);
	}

	public static void test1(){
		PersonDAO personDAO = GameBeanFactory.getPersonDAO();

		Pageable pageable = new PageRequest(0, 50);
//		Page<Person> rs = personDAO.findByAgeGreaterThan(1, pageable);
		Page<Person> rs = personDAO.findByFirstNameLike("ff", pageable);
//		Page<Person> rs = personDAO.findByAgeIs(1523, pageable);
//		Page<Person> rs = personDAO.findByAgeNot(333, pageable);
		System.out.println(rs);
		
		List<Person> list = rs.getContent();
		for(Person p : list){
			System.out.println(p);
		}
		System.out.println(list.size());
		personDAO.updateByDaily();
	}
	
	public static void test2(){
		PersonDAO personDAO = GameBeanFactory.getPersonDAO();
//		List<Person> list = personDAO.findByLastNameOrFirstName("lastN", "ffff");
//		List<Person> list = personDAO.findByLastNameIgnoreCase("last");
//		List<Person> list = personDAO.findDistinctPeopleByLastName("sdfsdf");
		List<Person> list = personDAO.findByAddressZipCode(new ZipCode("123456"));
		System.out.println(list.size());
		for(Person p : list){
			System.out.println(p);
		}
		
	}
	
}
